﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Data.SqlClient;
using System.Linq;
using System.Text;
using CRM.UTIL;

namespace CRM.DAL.Ali
{
    public class Ali_SupplierD : DBChannel
    {
        /// <summary>
        /// 可以在此选择数据库连接，默认为CRM
        /// </summary>
        public Ali_SupplierD() : base()
        {
        }


        #region 执行存储过程 Pro_GetAli_Supplier 

        /// <summary>
        /// 执行存储过程 Pro_GetAli_Supplier 
        ///xialei
        /// </summary>

        public DataTable ExecuteGetAli_Supplier(ref CRM.MODEL.Ali.GetAli_Supplier stu)
        {
            //存储过程参数	 		     
            this.sqlCmd.Parameters.Add(new SqlParameter(CRM.MODEL.Ali.GetAli_Supplier.IDPARM, SqlDbType.Int));
            this.sqlCmd.Parameters.Add(new SqlParameter(CRM.MODEL.Ali.GetAli_Supplier.PIDPARM, SqlDbType.Int));
            this.sqlCmd.Parameters.Add(new SqlParameter(CRM.MODEL.Ali.GetAli_Supplier.LOGINACCOUNTPARM, SqlDbType.VarChar));
            this.sqlCmd.Parameters.Add(new SqlParameter(CRM.MODEL.Ali.GetAli_Supplier.PASSWORDPARM, SqlDbType.VarChar));
            this.sqlCmd.Parameters.Add(new SqlParameter(CRM.MODEL.Ali.GetAli_Supplier.SUPPLIERNAMEPARM,
                SqlDbType.VarChar, 100));
            this.sqlCmd.Parameters.Add(new SqlParameter(CRM.MODEL.Ali.GetAli_Supplier.SUPPLIERLEVELPARM,
                SqlDbType.VarChar, 50));
            this.sqlCmd.Parameters.Add(new SqlParameter(CRM.MODEL.Ali.GetAli_Supplier.SUPPLIERCONTACTNAMEPARM,
                SqlDbType.VarChar, 100));
            this.sqlCmd.Parameters.Add(new SqlParameter(CRM.MODEL.Ali.GetAli_Supplier.SUPPLIERPHONEPARM,
                SqlDbType.VarChar, 50));
            this.sqlCmd.Parameters.Add(new SqlParameter(CRM.MODEL.Ali.GetAli_Supplier.SUPPLIERADDRESSPARM,
                SqlDbType.VarChar, 500));
            this.sqlCmd.Parameters.Add(new SqlParameter(CRM.MODEL.Ali.GetAli_Supplier.REMARKPARM, SqlDbType.VarChar));
            this.sqlCmd.Parameters.Add(new SqlParameter(CRM.MODEL.Ali.GetAli_Supplier.ISACTIVEPARM, SqlDbType.VarChar, 1));
            this.sqlCmd.Parameters.Add(new SqlParameter(CRM.MODEL.Ali.GetAli_Supplier.CREATEBYPARM, SqlDbType.VarChar,
                50));
            this.sqlCmd.Parameters.Add(new SqlParameter(CRM.MODEL.Ali.GetAli_Supplier.CREATETIMEPARM, SqlDbType.DateTime));
            this.sqlCmd.Parameters.Add(new SqlParameter(CRM.MODEL.Ali.GetAli_Supplier.LASTUPDATEBYPARM,
                SqlDbType.VarChar, 50));
            this.sqlCmd.Parameters.Add(new SqlParameter(CRM.MODEL.Ali.GetAli_Supplier.LASTUPDATETIMEPARM,
                SqlDbType.DateTime));

            //分页参数
            this.sqlCmd.Parameters.Add(new SqlParameter(CRM.MODEL.Ali.GetAli_Supplier.ORDERSTRING_PARM,
                SqlDbType.VarChar, 1000));
            this.sqlCmd.Parameters.Add(new SqlParameter(CRM.MODEL.Ali.GetAli_Supplier.PAGESIZE_PARM, SqlDbType.Int));
            this.sqlCmd.Parameters.Add(new SqlParameter(CRM.MODEL.Ali.GetAli_Supplier.CURRENTPAGEINDEX_PARM,
                SqlDbType.Int));
            this.sqlCmd.Parameters.Add(new SqlParameter(CRM.MODEL.Ali.GetAli_Supplier.TOTALITEMS_PARM, SqlDbType.Decimal));


            this.sqlCmd.Parameters.Add(new SqlParameter(CRM.MODEL.Ali.GetAli_Supplier.KEYVALUE_PARM, SqlDbType.VarChar));

            //设置参数的值
            this.sqlCmd.Parameters[CRM.MODEL.Ali.GetAli_Supplier.IDPARM].Value = stu.IDVALUE;
            this.sqlCmd.Parameters[CRM.MODEL.Ali.GetAli_Supplier.PIDPARM].Value = stu.PIDVALUE;
            this.sqlCmd.Parameters[CRM.MODEL.Ali.GetAli_Supplier.LOGINACCOUNTPARM].Value = stu.LOGINACCOUNTVALUE;
            this.sqlCmd.Parameters[CRM.MODEL.Ali.GetAli_Supplier.PASSWORDPARM].Value = stu.PASSWORDVALUE;
            this.sqlCmd.Parameters[CRM.MODEL.Ali.GetAli_Supplier.SUPPLIERNAMEPARM].Value = stu.SUPPLIERNAMEVALUE;
            this.sqlCmd.Parameters[CRM.MODEL.Ali.GetAli_Supplier.SUPPLIERLEVELPARM].Value = stu.SUPPLIERLEVELVALUE;
            this.sqlCmd.Parameters[CRM.MODEL.Ali.GetAli_Supplier.SUPPLIERCONTACTNAMEPARM].Value =
                stu.SUPPLIERCONTACTNAMEVALUE;
            this.sqlCmd.Parameters[CRM.MODEL.Ali.GetAli_Supplier.SUPPLIERPHONEPARM].Value = stu.SUPPLIERPHONEVALUE;
            this.sqlCmd.Parameters[CRM.MODEL.Ali.GetAli_Supplier.SUPPLIERADDRESSPARM].Value = stu.SUPPLIERADDRESSVALUE;
            this.sqlCmd.Parameters[CRM.MODEL.Ali.GetAli_Supplier.REMARKPARM].Value = stu.REMARKVALUE;
            this.sqlCmd.Parameters[CRM.MODEL.Ali.GetAli_Supplier.ISACTIVEPARM].Value = stu.ISACTIVEVALUE;
            this.sqlCmd.Parameters[CRM.MODEL.Ali.GetAli_Supplier.CREATEBYPARM].Value = stu.CREATEBYVALUE;
            this.sqlCmd.Parameters[CRM.MODEL.Ali.GetAli_Supplier.CREATETIMEPARM].Value = stu.CREATETIMEVALUE;
            this.sqlCmd.Parameters[CRM.MODEL.Ali.GetAli_Supplier.LASTUPDATEBYPARM].Value = stu.LASTUPDATEBYVALUE;
            this.sqlCmd.Parameters[CRM.MODEL.Ali.GetAli_Supplier.LASTUPDATETIMEPARM].Value = stu.LASTUPDATETIMEVALUE;


            this.sqlCmd.Parameters[CRM.MODEL.Ali.GetAli_Supplier.KEYVALUE_PARM].Value = stu.KEYVALUE_VALUE;

            //设置分页参数的值
            this.sqlCmd.Parameters[CRM.MODEL.Ali.GetAli_Supplier.ORDERSTRING_PARM].Value = stu.ORDERSTRING_VALUE;
            this.sqlCmd.Parameters[CRM.MODEL.Ali.GetAli_Supplier.PAGESIZE_PARM].Value = stu.PAGESIZE_VALUE;
            this.sqlCmd.Parameters[CRM.MODEL.Ali.GetAli_Supplier.CURRENTPAGEINDEX_PARM].Value =
                stu.CURRENTPAGEINDEX_VALUE;
            this.sqlCmd.Parameters[CRM.MODEL.Ali.GetAli_Supplier.TOTALITEMS_PARM].Value = stu.TOTALITEMS_VALUE;
            this.sqlCmd.Parameters[CRM.MODEL.Ali.GetAli_Supplier.TOTALITEMS_PARM].Direction = ParameterDirection.Output;

            //执行
            DataTable dt = this.GetDataByProcedure("dbo.Pro_GetAli_Supplier");
            //获取数据库的信息
            stu.TOTALITEMS_VALUE = this.sqlCmd.Parameters[CRM.MODEL.Ali.GetAli_Supplier.TOTALITEMS_PARM].Value;

            return dt;
        }

        #endregion


        #region 执行存储过程 Pro_EditAli_Supplier

        /// <summary>
        /// 执行存储过程 Pro_EditAli_Supplier 的相关参数
        ///xialei
        /// </summary>
        public int ExecuteEditAli_Supplier(ref CRM.MODEL.Ali.EditAli_Supplier stu)
        {
            if ((string) stu.ACTION_VALUE == "Update")
            {
                #region Update

                var sqlSb = new StringBuilder();
                sqlCmd.Parameters.Clear();
                sqlSb.Append(" UPDATE Ali_Supplier SET ");

                if (stu.ID_VALUE != DBNull.Value)
                {
                }
                if (stu.PID_VALUE != DBNull.Value)
                {

                    sqlSb.Append(" PID=@PID,");
                    sqlCmd.Parameters.Add(new SqlParameter("@PID", stu.PID_VALUE));
                }
                if (stu.LOGINACCOUNT_VALUE != DBNull.Value)
                {

                    sqlSb.Append(" LoginAccount=@LoginAccount,");
                    sqlCmd.Parameters.Add(new SqlParameter("@LOGINACCOUNT", stu.LOGINACCOUNT_VALUE));
                }
                if (stu.PASSWORD_VALUE != DBNull.Value)
                {

                    sqlSb.Append(" PassWord=@PassWord,");
                    sqlCmd.Parameters.Add(new SqlParameter("@PASSWORD", stu.PASSWORD_VALUE));
                }
                if (stu.SUPPLIERNAME_VALUE != DBNull.Value)
                {

                    sqlSb.Append(" SupplierName=@SupplierName,");
                    sqlCmd.Parameters.Add(new SqlParameter("@SUPPLIERNAME", stu.SUPPLIERNAME_VALUE));
                }
                if (stu.SUPPLIERLEVEL_VALUE != DBNull.Value)
                {

                    sqlSb.Append(" SupplierLevel=@SupplierLevel,");
                    sqlCmd.Parameters.Add(new SqlParameter("@SUPPLIERLEVEL", stu.SUPPLIERLEVEL_VALUE));
                }
                if (stu.SUPPLIERCONTACTNAME_VALUE != DBNull.Value)
                {

                    sqlSb.Append(" SupplierContactName=@SupplierContactName,");
                    sqlCmd.Parameters.Add(new SqlParameter("@SUPPLIERCONTACTNAME", stu.SUPPLIERCONTACTNAME_VALUE));
                }
                if (stu.SUPPLIERPHONE_VALUE != DBNull.Value)
                {

                    sqlSb.Append(" SupplierPhone=@SupplierPhone,");
                    sqlCmd.Parameters.Add(new SqlParameter("@SUPPLIERPHONE", stu.SUPPLIERPHONE_VALUE));
                }
                if (stu.SUPPLIERADDRESS_VALUE != DBNull.Value)
                {

                    sqlSb.Append(" SupplierAddress=@SupplierAddress,");
                    sqlCmd.Parameters.Add(new SqlParameter("@SUPPLIERADDRESS", stu.SUPPLIERADDRESS_VALUE));
                }
                if (stu.REMARK_VALUE != DBNull.Value)
                {

                    sqlSb.Append(" Remark=@Remark,");
                    sqlCmd.Parameters.Add(new SqlParameter("@REMARK", stu.REMARK_VALUE));
                }
                if (stu.ISACTIVE_VALUE != DBNull.Value)
                {

                    sqlSb.Append(" IsActive=@IsActive,");
                    sqlCmd.Parameters.Add(new SqlParameter("@ISACTIVE", stu.ISACTIVE_VALUE));
                }
                if (stu.CREATEBY_VALUE != DBNull.Value)
                {

                    sqlSb.Append(" CreateBy=@CreateBy,");
                    sqlCmd.Parameters.Add(new SqlParameter("@CREATEBY", stu.CREATEBY_VALUE));
                }
                if (stu.CREATETIME_VALUE != DBNull.Value)
                {

                    sqlSb.Append(" CreateTime=@CreateTime,");
                    sqlCmd.Parameters.Add(new SqlParameter("@CREATETIME", stu.CREATETIME_VALUE));
                }
                if (stu.LASTUPDATEBY_VALUE != DBNull.Value)
                {

                    sqlSb.Append(" LastUpdateBy=@LastUpdateBy,");
                    sqlCmd.Parameters.Add(new SqlParameter("@LASTUPDATEBY", stu.LASTUPDATEBY_VALUE));
                }
                if (stu.LASTUPDATETIME_VALUE != DBNull.Value)
                {

                    sqlSb.Append(" LastUpdateTime=@LastUpdateTime,");
                    sqlCmd.Parameters.Add(new SqlParameter("@LASTUPDATETIME", stu.LASTUPDATETIME_VALUE));
                }

                var sql = sqlSb.ToString().TrimEnd(',');

                sqlCmd.Parameters.Add(new SqlParameter("@ID", stu.ID_VALUE));
                //sqlCmd.CommandText = sqlSb.ToString();
                //sqlCmd.ExecuteNonQuery();
                int i = base.ExecuteSQL(sql + " WHERE ID=@ID");

                return i;

                #endregion
            }
            else
            {
                //动作参数
                this.sqlCmd.Parameters.Add(new SqlParameter(CRM.MODEL.Ali.EditAli_Supplier.ACTION_PARM,
                    SqlDbType.VarChar, 20));
                //错误信息参数
                this.sqlCmd.Parameters.Add(new SqlParameter(CRM.MODEL.Ali.EditAli_Supplier.ERRMSG_PARM,
                    SqlDbType.VarChar, 100));
                this.sqlCmd.Parameters.Add(new SqlParameter(CRM.MODEL.Ali.EditAli_Supplier.OUTID_PARM,
                    SqlDbType.Int));
                ////表字段参数
                this.sqlCmd.Parameters.Add(new SqlParameter(CRM.MODEL.Ali.EditAli_Supplier.IDPARM,
                    SqlDbType.Int));
                this.sqlCmd.Parameters.Add(new SqlParameter(CRM.MODEL.Ali.EditAli_Supplier.PIDPARM,
                    SqlDbType.Int));
                this.sqlCmd.Parameters.Add(new SqlParameter(CRM.MODEL.Ali.EditAli_Supplier.LOGINACCOUNTPARM,
                    SqlDbType.VarChar, 20));
                this.sqlCmd.Parameters.Add(new SqlParameter(CRM.MODEL.Ali.EditAli_Supplier.PASSWORDPARM,
                    SqlDbType.VarChar, 50));
                this.sqlCmd.Parameters.Add(new SqlParameter(CRM.MODEL.Ali.EditAli_Supplier.SUPPLIERNAMEPARM,
                    SqlDbType.VarChar, 100));
                this.sqlCmd.Parameters.Add(new SqlParameter(CRM.MODEL.Ali.EditAli_Supplier.SUPPLIERLEVELPARM,
                    SqlDbType.VarChar, 50));
                this.sqlCmd.Parameters.Add(
                    new SqlParameter(CRM.MODEL.Ali.EditAli_Supplier.SUPPLIERCONTACTNAMEPARM, SqlDbType.VarChar,
                        100));
                this.sqlCmd.Parameters.Add(new SqlParameter(CRM.MODEL.Ali.EditAli_Supplier.SUPPLIERPHONEPARM,
                    SqlDbType.VarChar, 50));
                this.sqlCmd.Parameters.Add(new SqlParameter(
                    CRM.MODEL.Ali.EditAli_Supplier.SUPPLIERADDRESSPARM, SqlDbType.VarChar, 500));
                this.sqlCmd.Parameters.Add(new SqlParameter(CRM.MODEL.Ali.EditAli_Supplier.REMARKPARM,
                    SqlDbType.VarChar));
                this.sqlCmd.Parameters.Add(new SqlParameter(CRM.MODEL.Ali.EditAli_Supplier.ISACTIVEPARM,
                    SqlDbType.VarChar, 1));
                this.sqlCmd.Parameters.Add(new SqlParameter(CRM.MODEL.Ali.EditAli_Supplier.CREATEBYPARM,
                    SqlDbType.VarChar, 50));
                this.sqlCmd.Parameters.Add(new SqlParameter(CRM.MODEL.Ali.EditAli_Supplier.CREATETIMEPARM,
                    SqlDbType.DateTime));
                this.sqlCmd.Parameters.Add(new SqlParameter(CRM.MODEL.Ali.EditAli_Supplier.LASTUPDATEBYPARM,
                    SqlDbType.VarChar, 50));
                this.sqlCmd.Parameters.Add(new SqlParameter(CRM.MODEL.Ali.EditAli_Supplier.LASTUPDATETIMEPARM,
                    SqlDbType.DateTime));



                this.sqlCmd.Parameters[CRM.MODEL.Ali.EditAli_Supplier.ACTION_PARM].Value = stu.ACTION_VALUE;
                this.sqlCmd.Parameters[CRM.MODEL.Ali.EditAli_Supplier.ERRMSG_PARM].Direction =
                    ParameterDirection.Output;
                this.sqlCmd.Parameters[CRM.MODEL.Ali.EditAli_Supplier.OUTID_PARM].Direction =
                    ParameterDirection.Output;
                //设置参数的值
                this.sqlCmd.Parameters[CRM.MODEL.Ali.EditAli_Supplier.IDPARM].Value = stu.ID_VALUE;
                this.sqlCmd.Parameters[CRM.MODEL.Ali.EditAli_Supplier.PIDPARM].Value = stu.PID_VALUE;
                this.sqlCmd.Parameters[CRM.MODEL.Ali.EditAli_Supplier.LOGINACCOUNTPARM].Value =
                    stu.LOGINACCOUNT_VALUE;
                this.sqlCmd.Parameters[CRM.MODEL.Ali.EditAli_Supplier.PASSWORDPARM].Value = stu.PASSWORD_VALUE;
                this.sqlCmd.Parameters[CRM.MODEL.Ali.EditAli_Supplier.SUPPLIERNAMEPARM].Value =
                    stu.SUPPLIERNAME_VALUE;
                this.sqlCmd.Parameters[CRM.MODEL.Ali.EditAli_Supplier.SUPPLIERLEVELPARM].Value =
                    stu.SUPPLIERLEVEL_VALUE;
                this.sqlCmd.Parameters[CRM.MODEL.Ali.EditAli_Supplier.SUPPLIERCONTACTNAMEPARM].Value =
                    stu.SUPPLIERCONTACTNAME_VALUE;
                this.sqlCmd.Parameters[CRM.MODEL.Ali.EditAli_Supplier.SUPPLIERPHONEPARM].Value =
                    stu.SUPPLIERPHONE_VALUE;
                this.sqlCmd.Parameters[CRM.MODEL.Ali.EditAli_Supplier.SUPPLIERADDRESSPARM].Value =
                    stu.SUPPLIERADDRESS_VALUE;
                this.sqlCmd.Parameters[CRM.MODEL.Ali.EditAli_Supplier.REMARKPARM].Value = stu.REMARK_VALUE;
                this.sqlCmd.Parameters[CRM.MODEL.Ali.EditAli_Supplier.ISACTIVEPARM].Value = stu.ISACTIVE_VALUE;
                this.sqlCmd.Parameters[CRM.MODEL.Ali.EditAli_Supplier.CREATEBYPARM].Value = stu.CREATEBY_VALUE;
                this.sqlCmd.Parameters[CRM.MODEL.Ali.EditAli_Supplier.CREATETIMEPARM].Value =
                    stu.CREATETIME_VALUE;
                this.sqlCmd.Parameters[CRM.MODEL.Ali.EditAli_Supplier.LASTUPDATEBYPARM].Value =
                    stu.LASTUPDATEBY_VALUE;
                this.sqlCmd.Parameters[CRM.MODEL.Ali.EditAli_Supplier.LASTUPDATETIMEPARM].Value =
                    stu.LASTUPDATETIME_VALUE;

                int i = this.ExecuteProcedure("dbo.Pro_EditAli_Supplier"); //执行	
                //获取数据库的信息
                stu.ERRMSG_VALUE = this.sqlCmd.Parameters[CRM.MODEL.Ali.EditAli_Supplier.ERRMSG_PARM].Value;
                return i;
            }
        }

        #endregion
    }
}